﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace ThisIsTheOnlyChamber
{
    public class Player
    {
        private readonly Camera cam;
        private float height;

        private readonly Vector3 min, max;

        public float verticalVelocity = 0.0f;

        public float X
        {
            get
            {
                return cam.position.X;
            }
            set
            {
                cam.position.X = value;
            }
        }

        public float Y
        {
            get
            {
                return cam.position.Y;
            }
            set
            {
                cam.position.Y = value + height;
            }
        }

        public float Z
        {
            get
            {
                return cam.position.Z;
            }
            set
            {
                cam.position.Z = value;
            }
        }

        public Matrix Projection
        {
            get
            {
                return cam.Projection;
            }
        }

        public Matrix View
        {
            get
            {
                return cam.View;
            }
        }

        public float AspectRatio
        {
            get
            {
                return cam.AspectRatio;
            }
            set
            {
                cam.AspectRatio = value;
            }
        }

        public Player(Vector3 position, float height)
        {
            this.height = height;
            cam = new Camera(new Vector3(position.X, position.Y + height, position.Z) );

            min = new Vector3(-9f, -height, -9f);
            max = new Vector3(9f, 0f, 9f);
        }

        public void MoveForward(float f)
        {
            cam.MoveForward(f);
        }

        public void Strafe(float f)
        {
            cam.Strafe(f);
        }

        public void MoveUp(float f)
        {
            cam.MoveUp(f);
        }

        public void LookUp(float f)
        {
            cam.ChangePhi(f);
        }

        public void LookRight(float f)
        {
            cam.ChangeTheta(f);
        }

        public void Jump()
        {
            if (Math.Abs(verticalVelocity) < 1f)
                verticalVelocity = 170f;
        }

        public BoundingBox BoundingBox()
        {
            return new BoundingBox(min + cam.position, max + cam.position);
        }
    }
}
